package com.cat.simulation;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-i/description/?envType=daily-question&envId=2025-09-02
 * @create 2025/9/2 11:15
 * @since JDK17
 */

public class Solution08 {
    public int numberOfPairs(int[][] points) {
        int n = points.length, ans = 0;
        Arrays.sort(points, (a, b) -> (a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]));
        for (int i = 0; i < n; i++) {
            int max = Integer.MIN_VALUE;
            for (int j = i + 1; j < n; j++) {
                if (points[j][1] > points[i][1]) {
                    continue;
                }
                if (points[j][1] > max) {
                    max = points[j][1];
                    ans++;
                }
            }
        }

        return ans;
    }
}
